//
//  ZJRefurbish.m
//  DreamSoftReimburse
//
//  Created by ZJ on 17/4/11.
//  Copyright © 2017年 ZJ. All rights reserved.
//

#import "ZJRefurbish.h"

@interface ZJRefurbish ()
/** Headerblock */
@property (nonatomic, copy) MyBolck headerBlock;
/** Footerblock */
@property (nonatomic, copy) MyBolck footerBlock;
@end

@implementation ZJRefurbish

- (void)headerToScollview:(UIScrollView *)view Block:(MyBolck)block {
    self.headerBlock = block;
    
    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadNewData方法）
    MJRefreshGifHeader *header =[MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerToReloadData)];
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 1; i < 27 ; i ++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"N%d",i]];
        [array addObject:image];
    }
//        NSRange range = NSMakeRange(0, 10);
//        NSArray *array1 = [NSArray arrayWithArray:[array subarrayWithRange:range]];
        // 设置普通状态的动画图片
    [header setImages:@[array[2]] forState:MJRefreshStateIdle];
//         设置即将刷新状态的动画图片（一松开就会刷新的状态）
    [header setImages:@[array[2]] forState:MJRefreshStatePulling];
//         设置正在刷新状态的动画图片
    [header setImages:array duration:1.5 forState:MJRefreshStateRefreshing];
    //     设置header
    view.mj_header = header;
    // 隐藏时间
    header.lastUpdatedTimeLabel.hidden = YES;
    // 隐藏状态
    //    header.stateLabel.hidden = YES;
    
}

- (void)footerToScollview:(UIScrollView *)view Block:(MyBolck)block{
    self.footerBlock = block;
    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadNewData方法）
    MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    view.mj_footer = footer;
    
}

- (void)headerToReloadData {
    if (self.headerBlock) {
        self.headerBlock();
    }
}

- (void)loadMoreData {
    if (self.footerBlock) {
        self.footerBlock();
    }
}
@end
